// pages/homepage/homepage.js
Page({
  data: {
    currentTime: '',
    timer: Number
  },

  onLoad: function () {
    this.startTimer();
  },

  updateDate: function () {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    var formatteTime = hour + ':' + (minute < 10 ? '0' + minute : minute) + ":" + (second < 10 ? '0' + second : second);
    var formattedDate = year + '年' + (month < 10 ? '0' + month : month) + '月' + (day < 10 ? '0' + day : day) + '日';

    this.setData({
      currentTime: formattedDate + ' ' + formatteTime
    });
  },

  startTimer: function () {
    this.data.timer = setInterval(() => {
      this.updateDate();
    }, 1000);
  },

  endTimer: function () {
    clearInterval(this.data.timer);
  },

  onUnload: function () {
    this.endTimer();
  },

  navigateToSendEmail: function () {
    wx.navigateTo({
      url: "/pages/sendemail/sendemail"
    });
  },

  navigateToWriteMessage: function () {
    wx.navigateTo({
      url: "/pages/writemessage/mainpage/mainpage"
    });
  },

  navigateToTurntable: function () {
    wx.navigateTo({
      url: "/pages/turntable/turntable"
    });
  }
})